package com.lb.annotationmapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.springframework.transaction.annotation.Transactional;

/**
 * MyBatis 全注解CRUD基础接口
 *
 * @param <T>
 * @author 作者 jacking
 * @ClassName: BaseMapperCRUD
 * @Description: TODO （描述）
 * @date 2017年6月23日 上午11:52:20
 */
@SuppressWarnings("all")
@Mapper
public interface BaseMapperCRUD<T> extends BaseMapperAnnotation {
    /**
     * 根据对象查询总数量
     *
     * @param obj
     * @return
     */
    @SelectProvider(type = ProviderTemplate.class, method = "count")
    public int count(Class clazz);

    /**
     * @param @param  countsql
     * @param @return 设定文件
     * @return long    返回类型
     * @throws
     * @Title: countBySql
     * @Description: TODO(这里用一句话描述这个方法的作用)
     */
    @SelectProvider(type = ProviderTemplate.class, method = "countBySql")
    public long countBySql(String countsql);

    /**
     * 根据id,查询设置对象类型
     *
     * @param clazz
     * @param id
     * @return
     */
    @SelectProvider(type = ProviderTemplate.class, method = "selectById")
    public Map selectById(Class clazz, String id);

    /**
     * @param obj
     * @return
     * @Description: select 根据对象查询
     */
    @SelectProvider(type = ProviderTemplate.class, method = "select")
    public T select(@Param("pojo") T obj);


    /**
     * @param obj
     * @return
     * @Description: select 根据对象查询所有
     */
    @SelectProvider(type = ProviderTemplate.class, method = "selectAll")
    public List<Map> selectAll(Class clazz);

    /**
     * Insert语句从ProviderTemplate类中生成
     * 返回mysql自增id_
     *
     * @param obj
     */
    @InsertProvider(type = ProviderTemplate.class, method = "insert")
    @Transactional
    public int insert(@Param("pojo") T obj);

    /**
    * @Description 插入参数Map类型的数据，转换为表字段处理
    * @Author jiaojing
    * @Date 2021/4/19 11:04
    * @param obj
    * @param tableName
    * @return int
    */
    @InsertProvider(type = ProviderTemplate.class, method = "insertMap")
    @Transactional
    public int insertMap(@Param("pojo") Map<String, Object> obj,@Param("tableName")String tableName);

    /**
     * Insert语句从ProviderTemplate类中生成
     * 返回mysql自增id
     *
     * @param obj
     */
    @InsertProvider(type = ProviderTemplate.class, method = "insert")
    @Options(useGeneratedKeys = true, keyProperty = "pojo.id")
    @Transactional
    public int insertReturnId(@Param("pojo") T obj);


    /**
     * Update语句从ProviderTemplate类中生成
     *
     * @param obj
     */
    @UpdateProvider(type = ProviderTemplate.class, method = "update")
    @Transactional
    public int update(@Param("pojo") T obj);
    /**
    * @Description 更新参数Map类型的数据，转换为表字段处理
    * @Author jiaojing
    * @Date 2021/4/19 10:45
    * @param obj
    * @param tableName
    * @return int
    */
    @UpdateProvider(type = ProviderTemplate.class, method = "updateMap")
    @Transactional
    public int updateMap(@Param("pojo") Map<String,Object> obj,@Param("tableName")String tableName);


    /**
     * Update语句从ProviderTemplate类中生成
     *
     * @param obj
     */
    @UpdateProvider(type = ProviderTemplate.class, method = "updateNew")
    @Transactional
    public int updateNew(@Param("pojo") T obj);


    /**
     * Delete语句从ProviderTemplate类中生成
     *
     * @param obj
     */
    @DeleteProvider(type = ProviderTemplate.class, method = "delete")
    @Transactional
    public int delete(@Param("pojo") T obj);

    /**
     * 根据id删除
     * Delete语句从ProviderTemplate类中生成
     *
     * @param obj
     */
    @DeleteProvider(type = ProviderTemplate.class, method = "deleteById")
    @Transactional
    public int deleteById(Class clazz, String id);

    /**
     * 按照并且更新条件updateNewByWhere语句从ProviderTemplate类中生成
     *
     * @param obj
     */
    @UpdateProvider(type = ProviderTemplate.class, method = "updateNewByWhere")
    @Transactional
    public int updateNewByWhere(@Param("pojo") T obj, @Param("where") Map<String, Object> whereMap);

    /**
     * 按照并且更新条件updateNewByWhereMap语句从ProviderTemplate类中生成
     *
     * @param obj
     */
    @UpdateProvider(type = ProviderTemplate.class, method = "updateNewByWhereMap")
    @Transactional
    public int updateNewByWhereMap(@Param("pojo") T pojo, @Param("whereMap") Map<String, Object> whereMap);

    /**
     * 按照并且更新条件updateNewByWhereSql语句从ProviderTemplate类中生成
     *
     * @param obj
     */
    @UpdateProvider(type = ProviderTemplate.class, method = "updateNewByWhereSql")
    @Transactional
    public int updateNewByWhereSql(T obj, String otherWhereSql);


}